//
//  TTPhotoEditViewController.m
//  TwentyThousandThomatoes
//
//  Created by lihux on 14-9-19.
//  Copyright (c) 2014年 lihux. All rights reserved.
//

#import "TTPhotoEditViewController.h"

#import "TTPhotoMaskView.h"
#import "TTDataSourceManager.h"
#import "TTI.h"
#import "NLImageCropperView.h"
#import "DataSourceManager.h"
#import "PostRequestionViewController.h"
#import "PostAnswerViewController.h"


@interface TTPhotoEditViewController ()
@property (nonatomic, strong) NLImageCropperView * imageCropper;
@end

@implementation TTPhotoEditViewController

- (void)viewDidLoad {
    [super viewDidLoad];

//    self.imageCropper = [[NLImageCropperView alloc] initWithFrame:self.view.bounds];
//    [self.view addSubview:_imageCropper];
//    [self.imageCropper setImage:self.originImage];
//    [self.imageCropper setCropRegionRect:CGRectMake(10, 50, 450, 680)];

    [self.imageView setImage:self.originImage];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

- (IBAction)btnSureCropedAction:(id)sender {

    [[DataSourceManager shareDataSourceManager] setSelectImage: self.imageCropper.getCroppedImage];

    [[DataSourceManager shareDataSourceManager] setHasSelectedImage:YES];

    NSArray * viewControllers = self.navigationController.viewControllers;
    UIViewController * targetViewController = nil;
    for (id controller in viewControllers) {
        if([controller isKindOfClass:[PostRequestionViewController class]]){
            targetViewController = controller;
            break;
        }
        // 利用通知模式传递数据
        if([controller isKindOfClass:[PostAnswerViewController class]]){

            NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
            [userInfo setObject:self.imageCropper.getCroppedImage forKey:@"imageData"];
            NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
            [notificationCenter postNotificationName:@"recvImagData" object:self userInfo:userInfo];

            targetViewController = controller;




            break;
        }
    }
    if(targetViewController){
     [self.navigationController popToViewController:targetViewController animated:YES];
    }
   
}
@end
